package com.aclass.xqx.classscreen.utlis;


import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.MediaType;

import android.os.Environment;
import android.util.Log;

import com.aclass.xqx.classscreen.db.StudentNews;
import com.aclass.xqx.classscreen.service.RemoteService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.FileCallBack;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * Created by Administrator on 2017/5/25.
 * 网络请求
 */

public class OkhttPost {

    public static void Okget(String url, int id, final Callback ca){
		OkHttpUtils.get().url(url).id(id).build().execute(new StringCallback() {
			@Override
			public void onError(Call call, Exception e, int id) {
				ca.onError(call,e,id);

			}
			@Override
			public void onResponse(String response, int id) {
				ca.onResponse(response,id);
			}
		});
	}
	public static void OkFile(String url, final FileCallBack callBack){
		OkHttpUtils.
				get()
				.url(url)
				.build()
				.execute(new com.zhy.http.okhttp.callback.FileCallBack(Environment.getExternalStorageDirectory().getPath()+"/Class", "Class.apk") {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        callBack.onError(call,e,id);
                    }

                    @Override
                    public void onResponse(File response, int id) {
                        callBack.onResponse(response,id);
                    }
                });
	}
	public static void Deleteget(String url, final String Nid , int id, final DeleteCallback ca, final String did, final String  name, final String time, final String content){

		OkHttpUtils.get().url(url).id(id).build().execute(new StringCallback() {
			@Override
			public void onError(Call call, Exception e, int id) {
				ca.onError(call,e,Nid,id,did,name,time,content);

			}

			@Override
			public void onResponse(String response, int id) {
				ca.onResponse(response,Nid,id,did,name,time,content);
			}
		});
	}


	public interface DeleteCallback {

		void onError(Call call, Exception e,String nid, int id,String did,String  name,  String time,  String content);

		void onResponse(String response,String nid, int id,String did,String  name,  String time,  String content);


	}

    public interface Callback {

         void onError(Call call, Exception e, int id);

         void onResponse(String response, int id);


    }
	public interface FileCallBack{
		void onError(Call call, Exception e, int id);
        void onResponse(File response, int id);
	}
}
